module sdldee.video.opengl;

import std.string;

import sdldee.c.sdl;
import sdldee.video.exception;

enum GlAttribute {
	RED_SIZE,
	GREEN_SIZE,
	BLUE_SIZE,
	ALPHA_SIZE,
	BUFFER_SIZE,
	DOUBLEBUFFER,
	DEPTH_SIZE,
	STENCIL_SIZE,
	ACCUM_RED_SIZE,
	ACCUM_GREEN_SIZE,
	ACCUM_BLUE_SIZE,
	ACCUM_ALPHA_SIZE,
	STEREO,
	MULTISAMPLEBUFFERS,
	MULTISAMPLESAMPLES,
	ACCELERATED_VISUAL,
	SWAP_CONTROL
}

void loadGlLibrary(char[] path) {
	if(SDL_GL_LoadLibrary(toStringz(path)) < 0)
		throw new VideoException("Unable to load OpenGL library");
}

void* getGlProcAddress(char[] proc) {
	void* ptr;
	if((ptr = SDL_GL_GetProcAddress(toStringz(proc))) == null)
		throw new VideoException("Unable to find OpenGL function " ~ proc);
	return ptr;
}

void setGlAttribute(GlAttribute attr, int value) {
	if(SDL_GL_SetAttribute(attr, value) < 0)
		throw new VideoException("Unable to set OpenGL attribute");
}

int getGlAttribute(GlAttribute attr) {
	int i;
	if(SDL_GL_GetAttribute(attr, &i) < 0)
		throw new VideoException("Unable to get OpenGL attribute");
	return i;
}

void swapGlBuffers() {
	SDL_GL_SwapBuffers();
}
